/**
 * This file is part of the Agora distribution. 
 * Detailed copyright and licensing information can be found
 * in the gpl-3.0.txt file which should be included in the distribution.
 * 
 * @version		$Id: 3.0.14 Olympus 2010-09-28 rammstein4o $
 * @copyright  2007 - 2010 jVitals
 * @license   GPLv3 Open Source
 * @link       http://jvitals.com
 * @since      File available since initial release
 */	

function agora_choose(type) {
	var choose_url = 'index.php?option=com_agora&task=maintenance&page=mergeusers&action=choose&tmpl=component&tp='+type;
	window.open(choose_url, '', "width=800,height=600")
}
function add_chosen(id, username, addtype) {
	if (parseInt(addtype) == 1) {
		var update_id = window.opener.document.getElementById('to_id');
		var update_uname = window.opener.document.getElementById('to_uname');
	} else {
		var update_id = window.opener.document.getElementById('from_id');
		var update_uname = window.opener.document.getElementById('from_uname');
	}
	update_id.innerHTML = id;
	update_uname.innerHTML = username;
	window.close();
}

function agora_merge() {
	var from_id = $('from_id').innerHTML;
	var from_uname = $('from_uname').innerHTML;
	var to_id = $('to_id').innerHTML;
	var to_uname = $('to_uname').innerHTML;
	if (from_id == '') {
		alert('Choose user to be merged');
		return false;
	}
	if (to_id == '') {
		alert('Choose user to merge to');
		return false;
	}

	var loading_message = 'Loading';
	var log = $('agora_log');
	log.innerHTML += '<div id="loading_icon"><img src="components/com_agora/image/loading.gif" alt="loading"/>'+loading_message+'</div>';
	new Fx.Scroll(log).toBottom();
	
	var data = {
		option : 'com_agora',
		task : 'maintenance',
		page : 'mergeusers',
		format : 'raw',
		action : 'merge',
		from_id : from_id,
		from_uname : from_uname,
		to_id : to_id,
		to_uname : to_uname,
	}

	new Ajax('index.php', {
		method: 'post',
		postBody: Object.toQueryString(data),
		onFailure: function(){},
		onComplete: function(inResponse) {
			$('loading_icon').remove();
			log.innerHTML += inResponse;
			new Fx.Scroll(log).toBottom();
		}
	}).request();	
	
}
